Skip to content

fix naturalsize ValueError for custom format strings with text (fixes #366) - #396

Open
aDragon0707 wants to merge 2 commits into
python-humanize:mainfrom
aDragon0707:fix-366
Open

fix naturalsize ValueError for custom format strings with text (fixes #366)#396
aDragon0707 wants to merge 2 commits into
python-humanize:mainfrom
aDragon0707:fix-366

Conversation

@aDragon0707

Copy link
Copy Markdown

Fixes #366.

naturalsize() raised ValueError for custom format strings with surrounding text (e.g. format="Size: %.1f"), because the rollover check passed the full formatted result to float().

  • The rollover step now tries to parse the formatted mantissa as a float and skips the rollover when the formatted result is not a plain number, preserving the pre-4.16 behavior for text formats.
  • Plain numeric formats keep the rollover behavior (999_999 -> "1.0 MB" still works).

Regression test added (test_naturalsize_custom_format_with_text): prefix and suffix cases.

tests/test_filesize.py → 77 passed, 0 failed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

naturalsize() raises ValueError for custom format strings with text

1 participant